package mail.server;

import java.util.Properties;

import javax.mail.Message;
import javax.mail.MessagingException;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.internet.AddressException;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;

public class TestMail {
	public static void main(String[] args) {
		String to = "zj13656800820@aliyun.com";
		String from = "13656800820@163.com";
		String host = "smtp.163.com";
		
		Properties properties = System.getProperties();
		properties.setProperty("mail.smtp.host", host);
		properties.setProperty("mail.smtp.auth", "true");
		
		Auther auther = new Auther("13656800820@163.com", "5201314Li.");
		Session session = Session.getDefaultInstance(properties,auther);

		try {
			MimeMessage message = new MimeMessage(session);
			message.setFrom(new InternetAddress(from));
			message.setRecipient(Message.RecipientType.TO, new InternetAddress(to));
			message.setSubject("这个是头部的主题部分");
			message.setContent("<h2>这个内容消息体部分</h2>","text/html;charset=utf-8");
			Transport.send(message);
			System.out.println("Sent message successfully....");	

		} catch (AddressException e) {
			e.printStackTrace();
		} catch (MessagingException e) {
			e.printStackTrace();
		}
		
	}
}
